/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Pedro
 */
public class DoubleLinkedList<E> extends AbstractList<E>{

        //Atributos
	protected DoublyLinkedNode<E> head, tail;
	protected int count;
	
        //Constructor
	public DoubleLinkedList()
	{
		head = null;
		tail = null;
		count = 0;
	}
	
        //Método para agregar un dato al principio de la lista.
	public void addFirst(E value)
	// pre: value is not null
	// post: adds element to head of list
	{
		// construct a new element, making it head
		head = new DoublyLinkedNode<E>(value, head, null);
		// fix tail, if necessary
		if (tail == null) tail = head;
		count++;
	}
	
        //Método para agregar un dato al final de la lista.
	public void addLast(E value)
	// pre: value is not null
	// post: adds new value to tail of list
	{
		// construct new element
		tail = new DoublyLinkedNode<E>(value, null, tail);
		// fix up head
		if (head == null) head = tail;
		count++;
	}
        
        //Método para remover un dato al final de la lista.
	public E removeLast()
	// pre: list is not empty
	// post: removes value from tail of list
	{
		DoublyLinkedNode<E> temp = tail;
		tail = tail.previous();
		if (tail == null) 
		{
			head = null;
		} 
		else 
		{
			tail.setNext(null);
		}
		count--;
		return temp.value();
	}
	
	//Verifica el tamaño.
	public int size() 
	{
		// TODO Auto-generated method stub
		return count;
	}

        //Obtiene el valor del último dato.
	public E getLast() 
	{
		// TODO Auto-generated method stub
		return tail.value();
	}
	
}

